package com.ruoyi.project.para.authorizer.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.para.authorizer.domain.BranchBankAuthorizer;
import com.ruoyi.project.para.authorizer.service.IBranchBankAuthorizerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 二级分行管理授权人员Controller
 *
 * @author ruoyi
 * @date 2020-03-14
 */
@Controller
@RequestMapping("/para/authorizer")
public class BranchBankAuthorizerController extends BaseController
{
    private String prefix = "para/authorizer";

    @Autowired
    private IBranchBankAuthorizerService branchBankAuthorizerService;

    @RequiresPermissions("para:authorizer:view")
    @GetMapping()
    public String authorizer()
    {
        return prefix + "/authorizer";
    }

    /**
     * 查询二级分行管理授权人员列表
     */
    @RequiresPermissions("para:authorizer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BranchBankAuthorizer branchBankAuthorizer)
    {
        startPage();
        List<BranchBankAuthorizer> list = branchBankAuthorizerService.list(new QueryWrapper<BranchBankAuthorizer>(branchBankAuthorizer));
        return getDataTable(list);
    }

    /**
     * 导出二级分行管理授权人员列表
     */
    @RequiresPermissions("para:authorizer:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BranchBankAuthorizer branchBankAuthorizer)
    {
        List<BranchBankAuthorizer> list = branchBankAuthorizerService.list(new QueryWrapper<BranchBankAuthorizer>(branchBankAuthorizer));
        ExcelUtil<BranchBankAuthorizer> util = new ExcelUtil<BranchBankAuthorizer>(BranchBankAuthorizer.class);
        return util.exportExcel(list, "authorizer");
    }

    /**
     * 新增二级分行管理授权人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存二级分行管理授权人员
     */
    @RequiresPermissions("para:authorizer:add")
    @Log(title = "二级分行管理授权人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BranchBankAuthorizer branchBankAuthorizer)
    {
        return toAjax(branchBankAuthorizerService.saveOrUpdate(branchBankAuthorizer));
    }

    /**
     * 修改二级分行管理授权人员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BranchBankAuthorizer branchBankAuthorizer = branchBankAuthorizerService.getById(id);
        mmap.put("branchBankAuthorizer", branchBankAuthorizer);
        return prefix + "/edit";
    }

    /**
     * 修改保存二级分行管理授权人员
     */
    @RequiresPermissions("para:authorizer:edit")
    @Log(title = "二级分行管理授权人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BranchBankAuthorizer branchBankAuthorizer)
    {
        return toAjax(branchBankAuthorizerService.saveOrUpdate(branchBankAuthorizer));
    }

    /**
     * 删除二级分行管理授权人员
     */
    @RequiresPermissions("para:authorizer:remove")
    @Log(title = "二级分行管理授权人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(branchBankAuthorizerService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
